package com.lancoo.znbkxx.teacher.aibkTestCoach.questionToMark.adapter

import android.text.Html
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.Type
import kotlinx.android.synthetic.main.aibk_adapter_answersheet_parent.view.*

/**
 * auther: 王国龙
 *  Date：2020.06.15
 * describe:
 */
class MarkAnswerSheetParentAdapter(
        val activity: AppCompatActivity,
        val typeList: MutableList<Type>
) : KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View {
        return LayoutInflater.from(activity)
                .inflate(R.layout.aibk_adapter_answersheet_parent, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        var typeIndex = typeList[position].TypeIndex
        var typeName = typeList[position].TypeName
        var genreName = typeList[position].GenreName
        holder.convertView.TvTypeInfor.text = Html.fromHtml(activity.resources.getString(R.string.aibk_answersheet_ques_infor,
                LancooMethod.numberToChinese(typeIndex), if (genreName.isEmpty()) typeName else genreName))
        val adapterChild = MarkAnswerSheetChildAdapter(
                activity, typeList, position
        )
        holder.convertView.RvAnswerSheetChild.adapter = adapterChild
        adapterChild.setClickChildListener(object : MarkAnswerSheetChildAdapter.OnClickChildListener {
            override fun onClick(
                    index_A: Int,
                    index_B: Int,
                    index_C: Int
            ) {
                clickParentListener!!.onClick(index_A, index_B, index_C)
            }
        })


    }

    override fun getItemCount(): Int {
        return typeList.size
    }

    interface OnClickParentListener {
        fun onClick(index_A: Int, index_B: Int, index_C: Int)
    }

    private var clickParentListener: OnClickParentListener? = null

    fun setClickParentListener(clickParentListener: OnClickParentListener?) {
        this.clickParentListener = clickParentListener
    }

}